package com.buanalintas.sandals.pos.item;

import com.buanalintas.bynga.Bynga;
import com.buanalintas.bynga.Logger;
import java.io.ObjectOutputStream;
import java.net.Socket;
/**
 *
 * @author Developer
 */
public class Printer {

    public static void print(String itemBarcode, String itemInformation) {
        try {
            String host = Bynga.getContextParameter("bynga.printer.host");
            int port = Integer.parseInt(Bynga.getContextParameter("bynga.printer.port"));
            Logger.getInstance().log1("Connecting to " + host + ":" + port);
            Socket socket = new Socket(host, port);
            Logger.getInstance().log1("Connected");
            Logger.getInstance().log1("Printing " + itemBarcode + " - " + itemInformation);
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject(itemBarcode);
            oos.writeObject(itemInformation);
            oos.flush();
            socket.close();
            Logger.getInstance().log1("Exiting...");
        } catch (Exception e) {
            Logger.getInstance().log(e);
        }
    }
}
